﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;

/// <summary>
/// Summary description for algemeen
/// </summary>
public class algemeen
{
	public algemeen()
	{
	}
    //public string sql_string = "Server=koen-laptop\\sqlexpress; DataBase=logistiek; Integrated Security=true; Connect Timeout=5;";
    //public string sql_string = "Server=hunzai\\sqlexpress; DataBase=logistiek; Integrated Security=true; Connect Timeout=5;";
    //public string sql_string = "Server=FRANKNOTEBOOK; DataBase=logistiek; Integrated Security=true; Connect Timeout=5;"


    public string sql_string = "Server=VPS-H4RZJMS4U3Q\\SQLEXPRESS; DataBase=logistiek; Integrated Security=false; Password=nomen ;User ID=nomennescio ;Connect Timeout=5;";



    public void status_update(string pakket_id, string status_id,bool aanmelding)
    {
        System.Data.SqlClient.SqlConnection sqlConnection1 =
            new System.Data.SqlClient.SqlConnection(sql_string);

        
        System.Data.SqlClient.SqlCommand cmd1 = new System.Data.SqlClient.SqlCommand();
        cmd1.CommandType = System.Data.CommandType.Text;
        System.Data.SqlClient.SqlDataReader lees1;
        string route_id = "";
        string query1 = "";
        if(aanmelding) query1 = "select TOP 1 route_id from route where pakket_id = '" + pakket_id + "'";
        else query1 = "select route_id from actuele_routes where pakket_id = '" + pakket_id + "'";
        cmd1.CommandText = query1;
        cmd1.Connection = sqlConnection1;
        sqlConnection1.Open();
        lees1 = cmd1.ExecuteReader();
        try
        {
            lees1.Read();
            route_id = lees1.GetSqlValue(0).ToString();
        }
        catch
        {
            route_id = "0";
        }
        lees1.Close();
        if (route_id == "0")
        {
            query1 = "select route_id from laatste_routes where pakket_id = '" + pakket_id + "'";
            cmd1.CommandText = query1;
            lees1 = cmd1.ExecuteReader();
            try
            {
                lees1.Read();
                route_id = lees1.GetSqlValue(0).ToString();
            }
            catch
            {
                route_id = "0";
            }
        }
        lees1.Close();
        string query2 = "EXEC [dbo].[Voetoe_status] @route_ID = '" + route_id + "', @status_ID = '" + status_id + "'";
        cmd1.CommandText = query2;
        cmd1.ExecuteNonQuery();
        cmd1.Connection.Close();
    }

        

}
